import 'package:flutter/material.dart';
import 'package:videodemo/z_video/zsn_video.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  String currentVideoUrl =
      'https://cesium.com/public/SandcastleSampleData/big-buck-bunny_trailer.mp4';
  String title = '大兔子';
  int currentVideoIndex = 0;
  void changeVideo(String videoUrl) {
    setState(() {
      currentVideoUrl = videoUrl;
    });
  }

  List videos = [
    'https://cesium.com/public/SandcastleSampleData/big-buck-bunny_trailer.mp4',
    'https://media.w3.org/2010/05/sintel/trailer.mp4',
    'https://alimov2.a.kwimgs.com/upic/2023/07/18/18/BMjAyMzA3MTgxODQ1MDFfMTE3MjIxNTM0Nl8xMDgyODA4MTQyMTRfMV8z_b_B72fb96ff8f36666481222eef1e0a6996.mp4?clientCacheKey=3xct7srh4s5ykcm_b.mp4&tt=b&di=65ed8104&bp=14214',
    'https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-360p.mp4',
    'https://www.w3schools.com/html/movie.mp4',
    'xxxxxx',
    'https://txmov2.a.kwimgs.com/upic/2024/10/10/15/BMjAyNDEwMTAxNTUxMTRfNjg2MDgzMDQ2XzE0NTc2NjEyOTI2Ml8xXzM=_b_B3b08fdb3c2d0befb1dee06a16790fe95.mp4?tag=1-1739604037-unknown-0-rbyrxsbsqf-4e4e9f60e5130f02&clientCacheKey=3xrssnqs6tm58ga_b.mp4&bp=10000&tt=b&ss=vp'
  ];
  List videosTitle = [
    '大兔子',
    '冰天雪地',
    '竖屏视频测试',
    '西瓜视频demo',
    '大灰熊',
    '错误地址测试',
    '竖屏视频测试2'
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('视频测试'),
      ),
      body: Column(
        children: [
          // VideoBase(videoUrl: currentVideoUrl),
          ZsnVideo(
            videoUrl: currentVideoUrl,
            title: title,
          ),
          Expanded(
              child: ListView.builder(
            itemCount: videos.length,
            itemBuilder: (context, index) {
              return Container(
                margin: EdgeInsets.all(5),
                decoration: BoxDecoration(
                    color: Colors.grey[100],
                    borderRadius: BorderRadius.circular(5),
                    // 阴影
                    boxShadow: [
                      BoxShadow(
                        // ignore: deprecated_member_use
                        color: Colors.grey.withOpacity(0.1),
                        spreadRadius: 5,
                        blurRadius: 7,
                        offset: Offset(1, 2),
                      )
                    ]),
                child: ListTile(
                    textColor:
                        currentVideoIndex == index ? Colors.red : Colors.black,
                    title: Text('${index + 1}、${videosTitle[index]}'),
                    onTap: () {
                      setState(() {
                        currentVideoIndex = index;
                        title = videosTitle[index];
                      });
                      changeVideo(videos[index]);
                    }),
              );
            },
          ))
        ],
      ),
    );
  }
}
